function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help untitled

% Last Modified by GUIDE v2.5 15-Mar-2015 18:00:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to untitled (see VARARGIN)

% Choose default command line output for untitled
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles) 
    defines = evalin('base', 'defines');
    sortOrder = splitStringToCells(defines.analysisSortArray);            
    
    [dataPathways, data, sorting] = loadOriginalData();
    handles.sortArray = sorting; 
                        
    handles.data = data;
    handles.dataPathways = dataPathways;
    
    names = {...
        '    PP FBA   ', ...
        '    SP FBA   ', ...
        ' Biomass FBA ', ...
        '  PP R count ', ...
        '  SP R count ', ...
        ' Reac weights', ...
        ' Met weights ', ...
        'Common weight', ...
        'PP ID', ...
        'SP ID'};
 
     if defines.analysisOption == '2'
        originalColumnNames = names;   
     else
        originalColumnNames = {'', '', '', '', '', '', '', '', '', ''};
        originalColumnNames{abs(str2num(sortOrder{1}))} = names{1};
        originalColumnNames{abs(str2num(sortOrder{2}))} = names{2};
        originalColumnNames{abs(str2num(sortOrder{3}))} = names{3};
        originalColumnNames{abs(str2num(sortOrder{4}))} = names{4};
        originalColumnNames{abs(str2num(sortOrder{5}))} = names{5};
        originalColumnNames{abs(str2num(sortOrder{6}))} = names{6};
        originalColumnNames{abs(str2num(sortOrder{7}))} = names{7};
        originalColumnNames{8} = names{8};
        originalColumnNames{9} = names{9};
        originalColumnNames{10} = names{10};
     end
    
                
    columnNames = originalColumnNames;

    handles.columnNames = columnNames;
    handles.originalColumnNames = originalColumnNames;
   
    guidata(hObject, handles);

    ReloadListData(hObject, handles)
    varargout{1} = handles.output;



function ReloadListData(hObject, handles)
     defines = evalin('base', 'defines');
if isequal(size(handles.data,1), 0)
    firstColumn{1} ='';
    secondColumn{1} = '';
    thirdColumn{1} = '';
    fourthColumn{1} ='';
    fiftColumn{1} ='';
    sixtColumn{1} ='';
    seventhColumn{1} ='';
    eightColumn{1} ='';
    idProd{1} ='';
    idSubs{1} ='';
else
   
     if defines.analysisOption == '1'
        [data, e] = sortrows(handles.data, handles.sortArray);
     else
          [data, e] = sortrows(handles.data, [-8]);
     end
    handles.data = data;

    firstColumn = cell(size(handles.data(:,abs(handles.sortArray(1)))));
    secondColumn = cell(size(handles.data(:,abs(handles.sortArray(2)))));
    thirdColumn = cell(size(handles.data(:,abs(handles.sortArray(3)))));
    fourthColumn = cell(size(handles.data(:,abs(handles.sortArray(4)))));
    fiftColumn = cell(size(handles.data(:,abs(handles.sortArray(5)))));
    sixtColumn = cell(size(handles.data(:,abs(handles.sortArray(6)))));
    seventhColumn = cell(size(handles.data(:,abs(handles.sortArray(7)))));
    eightColumn = cell(size(handles.data(:,abs(handles.sortArray(8)))));
    idProd = cell(size(handles.data(:,9)));
    idSubs = cell(size(handles.data(:,10)));

    for i=1:length(handles.data(:,2))
        firstColumn{i} = num2str(handles.data(i,abs(handles.sortArray(1))));
        secondColumn{i} = num2str(handles.data(i,abs(handles.sortArray(2))));
        thirdColumn{i} = num2str(handles.data(i,abs(handles.sortArray(3))));
        fourthColumn{i} = num2str(handles.data(i,abs(handles.sortArray(4))));
        fiftColumn{i} = num2str(handles.data(i,abs(handles.sortArray(5))));
        sixtColumn{i} = num2str(handles.data(i,abs(handles.sortArray(6))));
        seventhColumn{i} = num2str(handles.data(i,abs(handles.sortArray(7))));
        eightColumn{i} = num2str(handles.data(i,abs(handles.sortArray(8))));
        idProd{i} = num2str(handles.data(i,abs(handles.sortArray(9))));
        idSubs{i} = num2str(handles.data(i,abs(handles.sortArray(10))));
    end
    set(handles.edit1, 'String', '');
end
formattable(handles.listbox2, handles.columnNames, firstColumn, secondColumn,...
thirdColumn,fourthColumn,fiftColumn,sixtColumn, seventhColumn,eightColumn, idProd, idSubs);

set(handles.numberOfRoutesLabel, 'String', length(firstColumn));
set(handles.numberOfSelectedItems, 'String', 0);
guidata(hObject, handles);


 
function ExchangeColumns(hObject, handles)
first = handles.FirstColumn;
second = handles.SecondColumn;
sortArray = handles.sortArray;
columnNames = handles.columnNames;
dataArray = handles.data;

x = sortArray(first);
sortArray(first) = sortArray(second);
sortArray(second) = x;

x = columnNames(first);
columnNames(first) = columnNames(second);
columnNames(second) = x;

handles.sortArray = sortArray;
handles.columnNames = columnNames;
handles.data = dataArray;

ReloadListData(hObject, handles);
guidata(hObject, handles);        



function [analyzedPathways, data, sorting] = loadOriginalData()
    data = evalin('base','arrayOfAllPathwaysWeights');
    analyzedPathways = evalin('base','analyzedPathways');
    defines = evalin('base', 'defines');
    sortOrder = splitStringToCells(defines.analysisSortArray);
    
     if defines.analysisOption == '2'
        sortOrder = {'1', '2', '3', '4', '5', '6', '7'}     
     end
    
    sorting = [1 2 3 4 5 6 7 8 9 10];
    for is = 1: length(sortOrder)
        if str2num(sortOrder{is}) < 0
            sorting(is) = sorting(is) * -1;
        end
    end


%SELECT ALL BUTTON
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
values = [];
for i=3:str2num(get(handles.numberOfRoutesLabel, 'String')) + 2
  values =[values, i]; 
end
set(handles.listbox2, 'value', values);
set(handles.numberOfSelectedItems, 'String', str2num(get(handles.numberOfRoutesLabel, 'String')));

guidata(hObject, handles);



% --- Executes on button press in CLEAR ALL.
function pushbutton2_Callback(hObject, eventdata, handles)
set(handles.listbox2,'value', []);
set(handles.numberOfSelectedItems, 'String',0);

guidata(hObject, handles);

% --- Executes on SAVE RESULTS
function pushbutton3_Callback(hObject, eventdata, handles)
defines = evalin('base','defines');
assignin('base', 'columnNames',  handles.columnNames );
val = get(handles.listbox2,'value');
time = datestr(now,'mmmm dd, yyyy HH-MM-SS');
bar = waitbar(0,'Please wait... Getting pathways information and saving ..,');
for i=1:length(val)
    waitbar(i/length(val), bar, [num2str(i), ' Pathways of ', num2str(length(val)), ' total' ])
    drawnow

    indx = val(i) - 2;
    if indx<0
        indx = 0;
    end
    if indx>0
      value = 0;
      value2 = 0;
      pathIndex = 0 ;
      if str2num(defines.isProductUsed) & str2num(defines.isSubstrateUsed)
          for j=1:length( handles.dataPathways)
                p = handles.dataPathways(j);
                if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) %get value from list               
                    if p.NUMBER_OF_PATHWAY_PROD == handles.data(indx, 10) %get value from list
                        value = handles.data(indx, 9);
                        value2 = handles.data(indx, 10);
                        pathIndex = j;
                    end
                end
           end
      else
          for j=1:length( handles.dataPathways)
                p = handles.dataPathways(j);
                if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) %get value from list
                    value = indx;
                    pathIndex = indx;
                end
           end
      end
      
      assignin('base', 'dataValues',  handles.data(indx,:));

      %value - index in analyzedPathways
      print_results_of_pathway(value, value2, pathIndex, get(handles.checkbox1, 'Value'), time);
    else
        msgbx = msgbox('Please select value from the list');
    end
 end
close(bar)

% --- Executes on selection change in SELECT ITEM.
function listbox2_Callback(hObject, eventdata, handles)
    defines = evalin('base','defines');
    assignin('base', 'columnNames',  handles.columnNames );

    set(handles.edit1, 'String', '');
    val = get(handles.listbox2,'value');%

    disp('##############################################################');

    if(length(val)) > 1
        bar = waitbar(0,'Please wait... Getting pathways information');
    end
    set(handles.numberOfSelectedItems, 'String', length(val));

    for i=1:length(val)
         if(length(val)) > 1
            waitbar(i/length(val), bar, [num2str(i), ' Pathways of ', num2str(length(val)), ' total' ])
            drawnow
         end
        indx = val(i) - 2;
        if indx<0
            indx = 0;
        end
        if indx>0
            value = 0;
            value2 = 0;
            pathIndex = 0 ;

            if length(val) == 1
                set(handles.edit1, 'String', '');
            end

            outtext = get(handles.edit1,'String');

            if str2num(defines.isProductUsed) & str2num(defines.isSubstrateUsed)
              for j=1:length( handles.dataPathways)
                    p = handles.dataPathways(j);
                    if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) %get value from list                    
                        if p.NUMBER_OF_PATHWAY_PROD == handles.data(indx, 10) %get value from list
                            value = handles.data(indx, 9);
                            value2 = handles.data(indx, 10);
                            pathIndex = j;
                        end
                    end
               end
            else
              for j=1:length( handles.dataPathways)
                    p = handles.dataPathways(j);
                    if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) %get value from list
                        value = j;
                        pathIndex = j;
                    end
               end
            end

            assignin('base', 'dataValues',  handles.data(indx,:));

            str = print_results_of_pathway_to_results_windows(value, value2, pathIndex);
            set(handles.edit1, 'String', '');
            s = evalc('disp(outtext)');

            outtext = [str char(10) s];
            set(handles.edit1, 'String', outtext);

            guidata(hObject, handles);
            drawnow update
        end
    end
    if(length(val)) > 1
       close(bar)
    end    


% --- Executes on button press in visualizeButton.
function visualizeButton_Callback(hObject, eventdata, handles)
    defines = evalin('base','defines');
    val = get(handles.listbox2,'value');
    value = [];
    bar = waitbar(0,'Please wait... Getting pathways information and saving ..,');
    for i=1:length(val)
        waitbar(i/length(val), bar, [num2str(i), ' Pathways of ', num2str(length(val)), ' total' ])
        drawnow

        indx = val(i) - 2;
        if indx < 0
            indx = 0;
        end
        if indx > 0
            
            if str2num(defines.isProductUsed) & str2num(defines.isSubstrateUsed)
              for j=1:length(handles.dataPathways)
                    p = handles.dataPathways(j);
                    if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) && ...
                        p.NUMBER_OF_PATHWAY_PROD == handles.data(indx, 10) 
                            value = [value; p.NUMBER_OF_PATHWAY, p.NUMBER_OF_PATHWAY_PROD];
                    end
               end
            else
                for j=1:length( handles.dataPathways)
                    p = handles.dataPathways(j);
                    if p.NUMBER_OF_PATHWAY == handles.data(indx, 9) %get value from list
                         value = [value; p.NUMBER_OF_PATHWAY, 0];
                    end
                end
            end
        else
             msgbx = msgbox('Please select value from the list');
        end
    end

    createAndVisualizeGraph(value);
    close(bar)



function firstToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 1;
    handles.SecondColumn = 2;

    tmpMin = get(handles.min1column, 'String');
    tmpMax = get(handles.max1column, 'String');
    set(handles.min1column, 'String', get(handles.min2column, 'String'));
    set(handles.max1column, 'String', get(handles.max2column, 'String'));
    set(handles.min2column, 'String', tmpMin);
    set(handles.max2column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function secondToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 2;
    handles.SecondColumn = 1;

    tmpMin = get(handles.min2column, 'String');
    tmpMax = get(handles.max2column, 'String');
    set(handles.min2column, 'String', get(handles.min1column, 'String'));
    set(handles.max2column, 'String', get(handles.max1column, 'String'));
    set(handles.min1column, 'String', tmpMin);
    set(handles.max1column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function secondToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 2;
    handles.SecondColumn = 3;

    tmpMin = get(handles.min2column, 'String');
    tmpMax = get(handles.max2column, 'String');
    set(handles.min2column, 'String', get(handles.min3column, 'String'));
    set(handles.max2column, 'String', get(handles.max3column, 'String'));
    set(handles.min3column, 'String', tmpMin);
    set(handles.max3column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function thirdToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 3;
    handles.SecondColumn = 2;

    tmpMin = get(handles.min3column, 'String');
    tmpMax = get(handles.max3column, 'String');
    set(handles.min3column, 'String', get(handles.min2column, 'String'));
    set(handles.max3column, 'String', get(handles.max2column, 'String'));
    set(handles.min2column, 'String', tmpMin);
    set(handles.max2column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function thirdToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 3;
    handles.SecondColumn = 4;

    tmpMin = get(handles.min3column, 'String');
    tmpMax = get(handles.max3column, 'String');
    set(handles.min3column, 'String', get(handles.min4column, 'String'));
    set(handles.max3column, 'String', get(handles.max4column, 'String'));
    set(handles.min4column, 'String', tmpMin);
    set(handles.max4column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function fourthToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 4;
    handles.SecondColumn = 3;

    tmpMin = get(handles.min4column, 'String');
    tmpMax = get(handles.max4column, 'String');
    set(handles.min4column, 'String', get(handles.min3column, 'String'));
    set(handles.max4column, 'String', get(handles.max3column, 'String'));
    set(handles.min3column, 'String', tmpMin);
    set(handles.max3column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function fourthToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 4;
    handles.SecondColumn = 5;

    tmpMin = get(handles.min4column, 'String');
    tmpMax = get(handles.max4column, 'String');
    set(handles.min4column, 'String', get(handles.min5column, 'String'));
    set(handles.max4column, 'String', get(handles.max5column, 'String'));
    set(handles.min5column, 'String', tmpMin);
    set(handles.max5column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function eightToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 8;
    handles.SecondColumn = 7;

    tmpMin = get(handles.min8column, 'String');
    tmpMax = get(handles.max8column, 'String');
    set(handles.min8column, 'String', get(handles.min7column, 'String'));
    set(handles.max8column, 'String', get(handles.max7column, 'String'));
    set(handles.min7column, 'String', tmpMin);
    set(handles.max7column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);
    
function fiftToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 5;
    handles.SecondColumn = 4;

    tmpMin = get(handles.min5column, 'String');
    tmpMax = get(handles.max5column, 'String');
    set(handles.min5column, 'String', get(handles.min4column, 'String'));
    set(handles.max5column, 'String', get(handles.max4column, 'String'));
    set(handles.min4column, 'String', tmpMin);
    set(handles.max4column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function fiftToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 5;
    handles.SecondColumn = 6;

    tmpMin = get(handles.min5column, 'String');
    tmpMax = get(handles.max5column, 'String');
    set(handles.min5column, 'String', get(handles.min6column, 'String'));
    set(handles.max5column, 'String', get(handles.max6column, 'String'));
    set(handles.min6column, 'String', tmpMin);
    set(handles.max6column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);
    
function sixtToLeft_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 6;
    handles.SecondColumn = 5;

    tmpMin = get(handles.min6column, 'String');
    tmpMax = get(handles.max6column, 'String');
    set(handles.min6column, 'String', get(handles.min5column, 'String'));
    set(handles.max6column, 'String', get(handles.max5column, 'String'));
    set(handles.min5column, 'String', tmpMin);
    set(handles.max5column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);
    
function sixtToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 6;
    handles.SecondColumn = 7;

    tmpMin = get(handles.min6column, 'String');
    tmpMax = get(handles.max6column, 'String');
    set(handles.min6column, 'String', get(handles.min7column, 'String'));
    set(handles.max6column, 'String', get(handles.max7column, 'String'));
    set(handles.min7column, 'String', tmpMin);
    set(handles.max7column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function seventhToRight_Callback(hObject, eventdata, handles)
    handles.FirstColumn = 7;
    handles.SecondColumn = 8;

    tmpMin = get(handles.min7column, 'String');
    tmpMax = get(handles.max7column, 'String');
    set(handles.min7column, 'String', get(handles.min8column, 'String'));
    set(handles.max7column, 'String', get(handles.max8column, 'String'));
    set(handles.min8column, 'String', tmpMin);
    set(handles.max8column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

function seventhToLeft_Callback(hObject, eventdata, handles)
 handles.FirstColumn = 7;
    handles.SecondColumn = 6;

    tmpMin = get(handles.min7column, 'String');
    tmpMax = get(handles.max7column, 'String');
    set(handles.min7column, 'String', get(handles.min6column, 'String'));
    set(handles.max7column, 'String', get(handles.max6column, 'String'));
    set(handles.min6column, 'String', tmpMin);
    set(handles.max6column, 'String', tmpMax);

    guidata(hObject, handles);
    ExchangeColumns(hObject, handles);

    

%FILTER DATA
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
    outtext = get(handles.elementsFilter,'String');
    [row, col] = size(outtext);

    [pathways, pathwaysWeights, sorting] = loadOriginalData();

    indexes = [];
    indexes2 = [];
    if ~isequal(col,0)
        for i=1:length(pathways)
            pathway = pathways(i);
            elements = pathway.PATHWAY;

            pathwayElements = {};
            for j=1:length(elements)
                pathwayElements = [pathwayElements; elements{j}(1:6)];
            end

            isMemeber = all(ismember(outtext, pathwayElements));
            if(isMemeber)
                indexes = [indexes; pathway.NUMBER_OF_PATHWAY]; 
                indexes2 = [indexes2, 0];
                if any(strcmp('NUMBER_OF_PATHWAY_PROD',fieldnames(pathway)))
                    indexes2 = [indexes2; pathway.NUMBER_OF_PATHWAY_PROD];
                end
            else
                if any(strcmp('PATHWAY_PROD',fieldnames(pathway)))
                    elements = pathway.PATHWAY_PROD;

                    pathwayElements = {};
                    for j=1:length(elements)
                        pathwayElements = [pathwayElements; elements{j}(1:6)];
                    end

                    isMemeber = all(ismember(outtext, pathwayElements));
                    if(isMemeber)
                        indexes = [indexes; pathway.NUMBER_OF_PATHWAY]; 
                        indexes2 = [indexes2; pathway.NUMBER_OF_PATHWAY_PROD];
                    end
                end
            end
        end
    else
        indexes = pathwaysWeights(:, 9); 
        indexes2 = pathwaysWeights(:, 10);
    end
    
    value = [];
     for i=1:length(pathwaysWeights)
        for j=1:length(indexes)
            if indexes(j) == pathwaysWeights(i, 9) && indexes2(j) == pathwaysWeights(i, 10)
                
                shouldInclude = true;
                if ~isempty(get(handles.min1column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(1))) < str2num(get(handles.min1column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min2column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(2))) < str2num(get(handles.min2column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min3column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(3))) < str2num(get(handles.min3column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min4column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(4))) < str2num(get(handles.min4column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min5column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(5))) < str2num(get(handles.min5column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min6column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(6))) < str2num(get(handles.min6column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.min8column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(7))) < str2num(get(handles.min8column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max1column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(1))) > str2num(get(handles.max1column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max2column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(2))) > str2num(get(handles.max2column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max3column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(3))) > str2num(get(handles.max3column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max4column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(4))) > str2num(get(handles.max4column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max5column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(5))) > str2num(get(handles.max5column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max6column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(6))) > str2num(get(handles.max6column,'String'))
                        shouldInclude = false;
                    end
                end
                if ~isempty(get(handles.max8column,'String'))
                    if pathwaysWeights(i,abs(handles.sortArray(7))) > str2num(get(handles.max8column,'String'))
                        shouldInclude = false;
                    end
                end

                if shouldInclude
                    value = [value; pathwaysWeights(i, :)];
                end
            end
        end
     end

    handles.data = value;
    guidata(hObject, handles);
    ReloadListData(hObject, handles)


function UpdateOrder(hObject, handles, column)
    sortValue = handles.sortArray(column);
    handles.sortArray(column) = -sortValue;
    guidata(hObject, handles);
    ReloadListData(hObject, handles)

% --- Executes on button press in up1.
function up1_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 1);

% --- Executes on button press in up2.
function up2_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 2);

% --- Executes on button press in up3.
function up3_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 3);

% --- Executes on button press in up4.
function up4_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 4);

% --- Executes on button press in up8.
function up8_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 8);

function up6_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 6);

function up5_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 5);

% --- Executes on button press in up7.
function up7_Callback(hObject, eventdata, handles)
UpdateOrder(hObject, handles, 7);


% --- Executes on button press in RESET FILTER.
function pushbutton42_Callback(hObject, eventdata, handles)
set(handles.min1column, 'String', '');
set(handles.min2column, 'String', '');
set(handles.min3column, 'String', '');
set(handles.min4column, 'String', '');
set(handles.min5column, 'String', '');
set(handles.min6column, 'String', '');
set(handles.min8column, 'String', '');
set(handles.max1column, 'String', '');
set(handles.max2column, 'String', '');
set(handles.max3column, 'String', '');
set(handles.max4column, 'String', '');
set(handles.max5column, 'String', '');
set(handles.max6column, 'String', '');
set(handles.max8column, 'String', '');
set(handles.elementsFilter, 'String', '');

ResetData(hObject, handles)

function ResetData(hObject, handles)
    [dataPathways, data, sorting] = loadOriginalData();
    handles.data = data;
    handles.dataPathways = dataPathways;

    handles.columnNames = handles.originalColumnNames;
    handles.sortArray = sorting;
    guidata(hObject, handles);
    ReloadListData(hObject, handles)



function min5column_Callback(hObject, eventdata, handles)
function min5column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit16_Callback(hObject, eventdata, handles)
function max5column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max6column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min6column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max1column_Callback(hObject, eventdata, handles)
function max1column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min1column_Callback(hObject, eventdata, handles)
function min1column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min2column_Callback(hObject, eventdata, handles)
function min2column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max2column_Callback(hObject, eventdata, handles)
function max2column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min3column_Callback(hObject, eventdata, handles)
function min3column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max3column_Callback(hObject, eventdata, handles)
function max3column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min4column_Callback(hObject, eventdata, handles)
function min4column_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max4column_Callback(hObject, eventdata, handles)
function max4column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min8column_Callback(hObject, eventdata, handles)
function min8column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max8column_Callback(hObject, eventdata, handles)
function max8column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function listbox2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function checkbox1_Callback(hObject, eventdata, handles)
function elementsFilter_Callback(hObject, eventdata, handles)
function elementsFilter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function min6column_Callback(hObject, eventdata, handles)
function max6column_Callback(hObject, eventdata, handles)
function min7column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function max7column_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function seventhToLeft_CreateFcn(hObject, eventdata, handles)
function up7_CreateFcn(hObject, eventdata, handles)
function seventhToRight_CreateFcn(hObject, eventdata, handles)
